"use strict";

import Vue from 'vue';
import axios, { AxiosInstance } from 'axios';

let config = {
    baseURL: 'http://127.0.0.1:7001',
    timeout: 10 * 60 * 1000,
  // withCredentials: true, // Check cross-site Access-Control
};

const _axios = axios.create(config);

export function interceptorRequest(vm: Vue) {
    _axios.interceptors.request.use(
        function (config) {
            // Do something before request is sent
            return config;
        },
        function (error) {
            // Do something with request error
            return Promise.reject(error);
        }
    );
}
// Add a response interceptor
export function interceptorResponse(vm: Vue) {
    _axios.interceptors.response.use(
        function(response) {
            // Do something with response data
            return response;
        },
        function(error) {
            // Do something with response error
            return Promise.reject(error);
        }
    );
}



Object.defineProperties(Vue.prototype, {
    axios: {
      get() {
        return _axios;
      }
    },
    $axios: {
      get() {
        return _axios;
      }
    },
});

declare module 'vue/types/vue' {

    interface Vue {
        axios: AxiosInstance;
        $axios: AxiosInstance;
    }

}

export default _axios;
